home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / BUS / TMCM Software and Labs.sit / Software for TMCM 7_95 / Files for Lab 5 / ListSum < prev    next >
Text File  |  1994-04-16  |  2KB  |  62 lines

  1. ; Complete this program so that it will add up the list
  2. ; of numbers starting at the location with label "List".
  3. ; The list of numbers ends with a 0.  Your program should
  4. ; have a loop that gets the next number, checks if it
  5. ; is zero and jumps to a halt instruction if it is.  If
  6. ; the number is not zero, the loop should procede to add
  7. ; it to the "Sum" and then jump to the start of the loop
  8. ; for the next number.  (READ ALL COMMENTS BELOW BEFORE
  9. ; WORKING ON THIS.)
  10.  
  11.  
  12.         lod-c 0       ; Store the number 0 in location "Sum"
  13.         sto Sum       ; to get ready to start adding.
  14.  
  15.         lod-c List    ; Get the number "List" in memory location 
  16.         sto NextNum   ; and store it in memory location NextNum.
  17.                       ; (Remember that a label is really just a
  18.                       ; number!)
  19.  
  20. Loop:   lod-i NextNum ; Get the next number in the list.
  21.                       ; (Note the use of indirect addressing!)
  22.  
  23.         ???           ; DO YOUR STUFF HERE:
  24.                       ;    Test if the number is zero; if
  25.                       ;    it is, then end the program.
  26.                       ;    Otherwise, add the number to Sum,
  27.                       ;    then add 1 to NextNum, then
  28.                       ;    return to the start of the loop
  29.  
  30.  
  31. Done:   hlt           ; program ends if you jump to this location
  32.  
  33. NextNum: data         ; This location will hold the ADDRESS
  34.                       ; of the next number that needs to be
  35.                       ; added to the Sum.  At the beginning
  36.                       ; of the program, it is loaded with the
  37.                       ; number, List, which is the address of
  38.                       ; the first number to be added.  After
  39.                       ; each number is added, 1 should be
  40.                       ; added to NextNum to make it point to
  41.                       ; the next number in the list.
  42.  
  43. Sum:    data          ; At the end of the program, this
  44.                       ; location should hold the sum of the
  45.                       ; numbers in the list.  It is set to
  46.                       ; 0 at the start of the program, and
  47.                       ; then the numbers are added to it one
  48.                       ; by one.
  49.  
  50. List:   123           ; This is the list of numbers to be added
  51.         37
  52.         103
  53.         12
  54.         93
  55.         88
  56.         207
  57.         2
  58.         124
  59.         198
  60.         73
  61.         0             ; This 0 marks the end of the list
  62.